package org.jederik.studip.android.view;

import org.jederik.android.provider.StudIP;
import org.jederik.android.provider.StudIP.News;
import org.jederik.studip.android.R;
import org.jederik.studip.android.view.tools.ResourceActivity;
import org.jederik.studip.android.view.tools.FormatHelper;

import android.database.Cursor;
import android.widget.TextView;

/**
 * Zeigt einen Newsartikel an
 * @author Jann-Frederik Laß
 *
 */
public class ViewNews extends ResourceActivity {

	@Override
	public void initView() {
		// Layout laden:
		setContentView(R.layout.view_news);
	}

	@Override
	public void showData(Cursor cursor) {
		
		if (cursor == null || !cursor.moveToFirst()) {
			return;
		}
		
		// Überschrift in Überschriftenzeile einfügen:
		TextView topic = (TextView) findViewById(R.id.topic);
		topic.setText(cursor.getString(cursor.getColumnIndex(News.TOPIC)));
		
		// News-Inhalt in Inhaltszeile einfügen:
		TextView body = (TextView) findViewById(R.id.body);
		body.setText(cursor.getString(cursor.getColumnIndex(News.BODY)));
		
		// Verfasser in Verfasserzeile einfügen:
		TextView author = (TextView) findViewById(R.id.author);
		author.setText(cursor.getString(cursor.getColumnIndex(News.AUTHOR)));
		
		// Formatiertes Datum in Datumszeile einfügen:
		TextView date = (TextView) findViewById(R.id.date);
		String timestamp = cursor.getString(cursor.getColumnIndex(News.DATE));
		if (timestamp==null) timestamp = "0";
		date.setText(FormatHelper.formatDate(Integer.parseInt(timestamp)));
		
		// Bereich in Bereich-Zeile einfügen:
		TextView range = (TextView) findViewById(R.id.range);
		range.setText(cursor.getString(cursor.getColumnIndex(News.RANGE)));
		
	}

	@Override
	public String getType() {
		return StudIP.TYPE_NEWS;
	}

	@Override
	public String getId() {
		return getIntent().getData().getLastPathSegment();
	}

	@Override
	public boolean canBeVisited() {
		return true;
	}
}
